//
//  CollectionViewCell.m
//  TestCell
//
//  Created by mingyuZhou on 2017/9/18.
//  Copyright © 2017年 mingyuZhou. All rights reserved.
//
#define ZMY_CELLWIDTH self.bounds.size.width
#import "SDWebImageManager.h"
#import "CollectionViewCell.h"
#import "UIImageView+WebCache.h"

@implementation CollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self addCellUI];
    }
    return self;
}

- (void)addCellUI{
    _pic1 = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, ZMY_CELLWIDTH - 10, 70)];
    [self.contentView addSubview:_pic1];
    
    _storename = [[UILabel alloc]initWithFrame:CGRectMake(5, 75, ZMY_CELLWIDTH - 10, 20)];
    _storename.textAlignment = NSTextAlignmentCenter;
    [_storename setTextColor:[UIColor blackColor]];
    [self.contentView addSubview:_storename];
    
    _title = [[UILabel alloc]initWithFrame:CGRectMake(5, 95, ZMY_CELLWIDTH - 10, 20)];
    _title.textAlignment = NSTextAlignmentLeft;
    _title.font = [UIFont systemFontOfSize:13];
    [_title setTextColor:[UIColor grayColor]];
    [self.contentView addSubview:_title];
    
    _oprice = [[UILabel alloc]initWithFrame:CGRectMake(ZMY_CELLWIDTH / 2 +5, 120, ZMY_CELLWIDTH / 2, 20)];
    _oprice.textAlignment = NSTextAlignmentCenter;
    _oprice.font = [UIFont systemFontOfSize:11];
    [_oprice setTextColor:[UIColor grayColor]];
    [self.contentView addSubview:_oprice];
    
    _price = [[UILabel alloc]initWithFrame:CGRectMake(5, 120, ZMY_CELLWIDTH / 2, 20)];
    _price.textAlignment = NSTextAlignmentCenter;
    [_price setTextColor:[UIColor redColor]];
    [self.contentView addSubview:_price];
    
    _button = [[UIButton alloc]initWithFrame:CGRectMake(10, 150, ZMY_CELLWIDTH - 20, 30)];
    [_button setTitle:@"立即抢购" forState:UIControlStateNormal];
    [_button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    _button.layer.cornerRadius = 2.0;//2.0是圆角的弧度，根据需求自己更改
    _button.layer.borderWidth = 1.0f;//设置边框颜色
    
    [self.contentView addSubview:_button];
    
}

- (void)setModel:(CollectionModel *)model{
    _model = model;
    NSString * str = _model.pic1;
    NSString *str2 = [str stringByReplacingOccurrencesOfString:@"__ROOT__" withString:@""];
    [_pic1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.chaojihui123.com%@",str2]]];
    
    _storename.text = _model.storename;
    _title.text = _model.title;
    _oprice.text = [NSString stringWithFormat:@"门店价¥ %@",_model.oprice];
    _price.text = [NSString stringWithFormat:@"¥ %@",_model.price];
    
}


@end
